package com.isoft.controller.sys;

import com.isoft.bean.Result;
import com.isoft.anno.SysControllerLogAnnotation;
import com.isoft.bean.OprateType;
import com.isoft.bean.ResponseData;
import com.isoft.bean.SysType;
import com.isoft.controller.BaseController;
import com.isoft.entity.AirportChange;
import com.isoft.entity.PageBean;
import com.isoft.service.impl.AirportChangeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@Slf4j
@RestController
@RequestMapping("/sys/change")
public class AirportChangeController extends BaseController {
    @Autowired
    AirportChangeService airportChangeService;
    //分页查所有变更数据
    @GetMapping("/gets")
    public Result page(@RequestParam(defaultValue = "1") Integer page ,
                       @RequestParam(defaultValue = "10") Integer pageSize)
    {
        log.info("分页查询 ：{},{}" , page , pageSize);
        PageBean pageBean = airportChangeService.getAll(page , pageSize);
        return Result.success(pageBean);
    }
    //按目的地，机场代码分页查变更数据
    @GetMapping("/getscons")
    public Result page(@RequestParam(defaultValue = "1") Integer page ,
                       @RequestParam(defaultValue = "20") Integer pageSize,String cnnm,String frcd )
    {
        log.info("分页查询 ：{},{}" , page , pageSize);
        PageBean pageBean = airportChangeService.getByCons(page , pageSize,cnnm,frcd);
        return Result.success(pageBean);
    }
    //审核变更信息   未发布0--》已发布1
    @SysControllerLogAnnotation(sysType = SysType.SYSTEM, operateType = OprateType.REVIEW, desc = "航班变更发布状态审核")
    @PutMapping("/permit")
    public ResponseData<Boolean> changePermit(Integer id){
        return  returnBoolean(airportChangeService.changePermit(id));
    }
    //增加航班变更信息
    @SysControllerLogAnnotation(sysType = SysType.SUPER,operateType = OprateType.INSERT,desc = "插入航班变更数据")
    @PostMapping("/add")
    public ResponseData<Boolean> addChange(AirportChange airportChange){
        return  returnBoolean(airportChangeService.addChange(airportChange));
    }
    //删除航班变更信息（物理删除）
    @SysControllerLogAnnotation(sysType = SysType.SUPER,operateType = OprateType.DELETE,desc="删除航班变更数据")
    @DeleteMapping("/delete/{id}")
    public ResponseData<Boolean> deleteChange(@PathVariable Integer id){
        return  returnBoolean(airportChangeService.deleteChange(id));
    }
    //更新航班变更信息
    @SysControllerLogAnnotation(sysType = SysType.SUPER, operateType = OprateType.UPDATE, desc = "更新航班变更数据")
    @PutMapping("/update")
    public ResponseData<Boolean> updateChange(@RequestBody AirportChange airportChange){
        return  returnBoolean(airportChangeService.updateChange(airportChange));
    }
    //查询所有未发布航班变更信息
    @GetMapping("/unPermit")
    public ResponseData<Object> unPermit(){
        return returnObject(airportChangeService.unPermit());
    }
}
